package com.jiangyao.model.vo;

import com.jiangyao.common.utils.FtpClient;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.Serializable;

/**
 * 文件VO
 *
 * @author: yangyongchuan
 * @create: 2020年08月09日 15:44
 */
@Data
@Builder
@ApiModel(value = "文件")
public class FileVO implements Serializable {
	private static final long serialVersionUID = -7027366562697259187L;
	@ApiModelProperty("存放路径")
	private String path;
	@ApiModelProperty("访问路径")
	private String url;
	@ApiModelProperty("文件名称")
	private String fileName;
	@ApiModelProperty("大小")
	private long size;
	@ApiModelProperty("后缀")
	private String suffix;

	/**
	 * 文件上传对象转换
	 *
	 * @param file 文件
	 * @param path 路径
	 * @return 结果
	 */
	public static FileVO convertFileVO(MultipartFile file, String path) {
		return FileVO.builder().path(path).url(FtpClient.fullFtpUrl(path)).fileName(file.getOriginalFilename())
				.size(file.getSize()).suffix(FilenameUtils.getExtension(file.getOriginalFilename())).build();
	}

}
